package GUI;

import java.awt.*;
import javax.swing.*;

public class ScriptPanel extends JPanel
{
	private int t;
	private String temp[],texts[];
	private Color color;
	private ImageIcon icon;
	
	public ScriptPanel()
	{
		texts = new String[4];
		color = Color.white;
		
		for (int i = 0;i < 4;i++)
		{
			texts[i] = "";
		}
		
		setOpaque(false);
		setPreferredSize(new Dimension(752,184));
		setVisible(true);
	}
	
	public void setColor(int i)
	{
		switch(i)
		{
		case 0:
			color = Color.WHITE;
			break;
		case 1:
			color = Color.RED;
			break;
		case 2:
			color = Color.ORANGE;
			break;
		case 3:
			color = Color.YELLOW;
			break;
		case 4:
			color = Color.GREEN;
			break;
		case 5:
			color = Color.BLUE;
			break;
		case 6:
			color = Color.CYAN;
			break;
		case 7:
			color = Color.GRAY;
			break;
		case 8:
			color = Color.BLACK;
			break;
		default:
		}
	}
	
	public void setText(String s)
	{
		t = 0;
		
		for (int i = 0;i < 4;i++)
		{
			texts[i] = "";
		}
		
		temp = s.split("\n",0);
		
		for (int i = 0;i < temp.length;i++)
		{
			while (temp[i].length() > 28)
			{
				texts[t++] = temp[i].substring(0,28);
				temp[i] = temp[i].substring(28);
			}
			
			texts[t++] = temp[i];
		}
		
		repaint();
	}
	
	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		icon = new ImageIcon("data\\system\\MESS.png");
		g.drawImage(icon.getImage(),0,0,null);
		g.setColor(color);
		g.setFont(new Font("Monospaced",Font.BOLD,24));
		
		for (int i = 0;i < 4;i++)
		{
			g.drawString(texts[i],17,38 * i + 39);
		}
		
		g.setColor(Color.WHITE);
		g.setFont(new Font("Monospaced",Font.BOLD,24));
		
		for (int i = 0;i < 4;i++)
		{
			g.drawString(texts[i],16,38 * i + 38);
		}
	}
}